package com.gaojinqi.sys.core.auth.util;

import com.gaojinqi.base.core.util.SpringContextHolder;

import java.util.Objects;

/**
 * 登录上下文持有者
 *
 * @author gaojinqi
 * @version 1.0
 * @since 2020年04月20日
 */
public class LoginContextHolder {

    private static LoginContext LOGIN_CONTEXT;

    public static void setContext(LoginContext loginContext) {
        LOGIN_CONTEXT = Objects.requireNonNull(loginContext, "loginContext can't be null");
    }

    public static LoginContext getContext() {
        if (LOGIN_CONTEXT == null) {
            synchronized (LoginContextHolder.class) {
                if (LOGIN_CONTEXT == null) {
                    LOGIN_CONTEXT = SpringContextHolder.getBean(LoginContext.class);
                }
            }
        }
        return LOGIN_CONTEXT;
    }

}
